public class demo1 {
    public String longestPalindrome(String s) {
        int n=s.length();
        int left=0;
        int right=0;
        String ret="";
        for(int i=0;i<n;i++){
            left=i;
            right=i;
            while(left>=0&&right<n&&s.charAt(left)==s.charAt(right)){
                left--;
                right++;
            }
            if(right-left-1>ret.length())ret=s.substring(left+1,right);
            left=i;
            right=i+1;
            while(left>=0&&right<n&&s.charAt(left)==s.charAt(right)){
                left--;
                right++;
            }
            if(right-left-1>ret.length())ret=s.substring(left+1,right);
        }
        return ret;
    }
}
